Option Strict On
Option Explicit On 

Public Class FDetail
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents btnApply As System.Windows.Forms.Button
    Friend WithEvents btnOk As System.Windows.Forms.Button
    Friend WithEvents btnCancel As System.Windows.Forms.Button
    Friend WithEvents UDetail1 As Avand.UDetail
    Friend WithEvents USection1 As Avand.USection
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(FDetail))
        Me.btnApply = New System.Windows.Forms.Button
        Me.btnOk = New System.Windows.Forms.Button
        Me.btnCancel = New System.Windows.Forms.Button
        Me.UDetail1 = New Avand.UDetail
        Me.USection1 = New Avand.USection
        Me.SuspendLayout()
        '
        'btnApply
        '
        Me.btnApply.AccessibleDescription = resources.GetString("btnApply.AccessibleDescription")
        Me.btnApply.AccessibleName = resources.GetString("btnApply.AccessibleName")
        Me.btnApply.Anchor = CType(resources.GetObject("btnApply.Anchor"), System.Windows.Forms.AnchorStyles)
        Me.btnApply.BackgroundImage = CType(resources.GetObject("btnApply.BackgroundImage"), System.Drawing.Image)
        Me.btnApply.Dock = CType(resources.GetObject("btnApply.Dock"), System.Windows.Forms.DockStyle)
        Me.btnApply.Enabled = CType(resources.GetObject("btnApply.Enabled"), Boolean)
        Me.btnApply.FlatStyle = CType(resources.GetObject("btnApply.FlatStyle"), System.Windows.Forms.FlatStyle)
        Me.btnApply.Font = CType(resources.GetObject("btnApply.Font"), System.Drawing.Font)
        Me.btnApply.Image = CType(resources.GetObject("btnApply.Image"), System.Drawing.Image)
        Me.btnApply.ImageAlign = CType(resources.GetObject("btnApply.ImageAlign"), System.Drawing.ContentAlignment)
        Me.btnApply.ImageIndex = CType(resources.GetObject("btnApply.ImageIndex"), Integer)
        Me.btnApply.ImeMode = CType(resources.GetObject("btnApply.ImeMode"), System.Windows.Forms.ImeMode)
        Me.btnApply.Location = CType(resources.GetObject("btnApply.Location"), System.Drawing.Point)
        Me.btnApply.Name = "btnApply"
        Me.btnApply.RightToLeft = CType(resources.GetObject("btnApply.RightToLeft"), System.Windows.Forms.RightToLeft)
        Me.btnApply.Size = CType(resources.GetObject("btnApply.Size"), System.Drawing.Size)
        Me.btnApply.TabIndex = CType(resources.GetObject("btnApply.TabIndex"), Integer)
        Me.btnApply.Text = resources.GetString("btnApply.Text")
        Me.btnApply.TextAlign = CType(resources.GetObject("btnApply.TextAlign"), System.Drawing.ContentAlignment)
        Me.btnApply.Visible = CType(resources.GetObject("btnApply.Visible"), Boolean)
        '
        'btnOk
        '
        Me.btnOk.AccessibleDescription = resources.GetString("btnOk.AccessibleDescription")
        Me.btnOk.AccessibleName = resources.GetString("btnOk.AccessibleName")
        Me.btnOk.Anchor = CType(resources.GetObject("btnOk.Anchor"), System.Windows.Forms.AnchorStyles)
        Me.btnOk.BackgroundImage = CType(resources.GetObject("btnOk.BackgroundImage"), System.Drawing.Image)
        Me.btnOk.Dock = CType(resources.GetObject("btnOk.Dock"), System.Windows.Forms.DockStyle)
        Me.btnOk.Enabled = CType(resources.GetObject("btnOk.Enabled"), Boolean)
        Me.btnOk.FlatStyle = CType(resources.GetObject("btnOk.FlatStyle"), System.Windows.Forms.FlatStyle)
        Me.btnOk.Font = CType(resources.GetObject("btnOk.Font"), System.Drawing.Font)
        Me.btnOk.Image = CType(resources.GetObject("btnOk.Image"), System.Drawing.Image)
        Me.btnOk.ImageAlign = CType(resources.GetObject("btnOk.ImageAlign"), System.Drawing.ContentAlignment)
        Me.btnOk.ImageIndex = CType(resources.GetObject("btnOk.ImageIndex"), Integer)
        Me.btnOk.ImeMode = CType(resources.GetObject("btnOk.ImeMode"), System.Windows.Forms.ImeMode)
        Me.btnOk.Location = CType(resources.GetObject("btnOk.Location"), System.Drawing.Point)
        Me.btnOk.Name = "btnOk"
        Me.btnOk.RightToLeft = CType(resources.GetObject("btnOk.RightToLeft"), System.Windows.Forms.RightToLeft)
        Me.btnOk.Size = CType(resources.GetObject("btnOk.Size"), System.Drawing.Size)
        Me.btnOk.TabIndex = CType(resources.GetObject("btnOk.TabIndex"), Integer)
        Me.btnOk.Text = resources.GetString("btnOk.Text")
        Me.btnOk.TextAlign = CType(resources.GetObject("btnOk.TextAlign"), System.Drawing.ContentAlignment)
        Me.btnOk.Visible = CType(resources.GetObject("btnOk.Visible"), Boolean)
        '
        'btnCancel
        '
        Me.btnCancel.AccessibleDescription = resources.GetString("btnCancel.AccessibleDescription")
        Me.btnCancel.AccessibleName = resources.GetString("btnCancel.AccessibleName")
        Me.btnCancel.Anchor = CType(resources.GetObject("btnCancel.Anchor"), System.Windows.Forms.AnchorStyles)
        Me.btnCancel.BackgroundImage = CType(resources.GetObject("btnCancel.BackgroundImage"), System.Drawing.Image)
        Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.btnCancel.Dock = CType(resources.GetObject("btnCancel.Dock"), System.Windows.Forms.DockStyle)
        Me.btnCancel.Enabled = CType(resources.GetObject("btnCancel.Enabled"), Boolean)
        Me.btnCancel.FlatStyle = CType(resources.GetObject("btnCancel.FlatStyle"), System.Windows.Forms.FlatStyle)
        Me.btnCancel.Font = CType(resources.GetObject("btnCancel.Font"), System.Drawing.Font)
        Me.btnCancel.Image = CType(resources.GetObject("btnCancel.Image"), System.Drawing.Image)
        Me.btnCancel.ImageAlign = CType(resources.GetObject("btnCancel.ImageAlign"), System.Drawing.ContentAlignment)
        Me.btnCancel.ImageIndex = CType(resources.GetObject("btnCancel.ImageIndex"), Integer)
        Me.btnCancel.ImeMode = CType(resources.GetObject("btnCancel.ImeMode"), System.Windows.Forms.ImeMode)
        Me.btnCancel.Location = CType(resources.GetObject("btnCancel.Location"), System.Drawing.Point)
        Me.btnCancel.Name = "btnCancel"
        Me.btnCancel.RightToLeft = CType(resources.GetObject("btnCancel.RightToLeft"), System.Windows.Forms.RightToLeft)
        Me.btnCancel.Size = CType(resources.GetObject("btnCancel.Size"), System.Drawing.Size)
        Me.btnCancel.TabIndex = CType(resources.GetObject("btnCancel.TabIndex"), Integer)
        Me.btnCancel.Text = resources.GetString("btnCancel.Text")
        Me.btnCancel.TextAlign = CType(resources.GetObject("btnCancel.TextAlign"), System.Drawing.ContentAlignment)
        Me.btnCancel.Visible = CType(resources.GetObject("btnCancel.Visible"), Boolean)
        '
        'UDetail1
        '
        Me.UDetail1.AccessibleDescription = resources.GetString("UDetail1.AccessibleDescription")
        Me.UDetail1.AccessibleName = resources.GetString("UDetail1.AccessibleName")
        Me.UDetail1.Anchor = CType(resources.GetObject("UDetail1.Anchor"), System.Windows.Forms.AnchorStyles)
        Me.UDetail1.AutoScroll = CType(resources.GetObject("UDetail1.AutoScroll"), Boolean)
        Me.UDetail1.AutoScrollMargin = CType(resources.GetObject("UDetail1.AutoScrollMargin"), System.Drawing.Size)
        Me.UDetail1.AutoScrollMinSize = CType(resources.GetObject("UDetail1.AutoScrollMinSize"), System.Drawing.Size)
        Me.UDetail1.BackgroundImage = CType(resources.GetObject("UDetail1.BackgroundImage"), System.Drawing.Image)
        Me.UDetail1.Dock = CType(resources.GetObject("UDetail1.Dock"), System.Windows.Forms.DockStyle)
        Me.UDetail1.Enabled = CType(resources.GetObject("UDetail1.Enabled"), Boolean)
        Me.UDetail1.Font = CType(resources.GetObject("UDetail1.Font"), System.Drawing.Font)
        Me.UDetail1.ImeMode = CType(resources.GetObject("UDetail1.ImeMode"), System.Windows.Forms.ImeMode)
        Me.UDetail1.Location = CType(resources.GetObject("UDetail1.Location"), System.Drawing.Point)
        Me.UDetail1.Name = "UDetail1"
        Me.UDetail1.RightToLeft = CType(resources.GetObject("UDetail1.RightToLeft"), System.Windows.Forms.RightToLeft)
        Me.UDetail1.Size = CType(resources.GetObject("UDetail1.Size"), System.Drawing.Size)
        Me.UDetail1.TabIndex = CType(resources.GetObject("UDetail1.TabIndex"), Integer)
        Me.UDetail1.Visible = CType(resources.GetObject("UDetail1.Visible"), Boolean)
        '
        'USection1
        '
        Me.USection1.AccessibleDescription = resources.GetString("USection1.AccessibleDescription")
        Me.USection1.AccessibleName = resources.GetString("USection1.AccessibleName")
        Me.USection1.Anchor = CType(resources.GetObject("USection1.Anchor"), System.Windows.Forms.AnchorStyles)
        Me.USection1.AutoScroll = CType(resources.GetObject("USection1.AutoScroll"), Boolean)
        Me.USection1.AutoScrollMargin = CType(resources.GetObject("USection1.AutoScrollMargin"), System.Drawing.Size)
        Me.USection1.AutoScrollMinSize = CType(resources.GetObject("USection1.AutoScrollMinSize"), System.Drawing.Size)
        Me.USection1.BackgroundImage = CType(resources.GetObject("USection1.BackgroundImage"), System.Drawing.Image)
        Me.USection1.Dock = CType(resources.GetObject("USection1.Dock"), System.Windows.Forms.DockStyle)
        Me.USection1.Enabled = CType(resources.GetObject("USection1.Enabled"), Boolean)
        Me.USection1.Font = CType(resources.GetObject("USection1.Font"), System.Drawing.Font)
        Me.USection1.ImeMode = CType(resources.GetObject("USection1.ImeMode"), System.Windows.Forms.ImeMode)
        Me.USection1.Location = CType(resources.GetObject("USection1.Location"), System.Drawing.Point)
        Me.USection1.Name = "USection1"
        Me.USection1.RightToLeft = CType(resources.GetObject("USection1.RightToLeft"), System.Windows.Forms.RightToLeft)
        Me.USection1.Size = CType(resources.GetObject("USection1.Size"), System.Drawing.Size)
        Me.USection1.TabIndex = CType(resources.GetObject("USection1.TabIndex"), Integer)
        Me.USection1.Visible = CType(resources.GetObject("USection1.Visible"), Boolean)
        '
        'FDetail
        '
        Me.AcceptButton = Me.btnOk
        Me.AccessibleDescription = resources.GetString("$this.AccessibleDescription")
        Me.AccessibleName = resources.GetString("$this.AccessibleName")
        Me.AutoScaleBaseSize = CType(resources.GetObject("$this.AutoScaleBaseSize"), System.Drawing.Size)
        Me.AutoScroll = CType(resources.GetObject("$this.AutoScroll"), Boolean)
        Me.AutoScrollMargin = CType(resources.GetObject("$this.AutoScrollMargin"), System.Drawing.Size)
        Me.AutoScrollMinSize = CType(resources.GetObject("$this.AutoScrollMinSize"), System.Drawing.Size)
        Me.BackgroundImage = CType(resources.GetObject("$this.BackgroundImage"), System.Drawing.Image)
        Me.CancelButton = Me.btnCancel
        Me.ClientSize = CType(resources.GetObject("$this.ClientSize"), System.Drawing.Size)
        Me.Controls.Add(Me.USection1)
        Me.Controls.Add(Me.UDetail1)
        Me.Controls.Add(Me.btnApply)
        Me.Controls.Add(Me.btnOk)
        Me.Controls.Add(Me.btnCancel)
        Me.Enabled = CType(resources.GetObject("$this.Enabled"), Boolean)
        Me.Font = CType(resources.GetObject("$this.Font"), System.Drawing.Font)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.ImeMode = CType(resources.GetObject("$this.ImeMode"), System.Windows.Forms.ImeMode)
        Me.Location = CType(resources.GetObject("$this.Location"), System.Drawing.Point)
        Me.MaximizeBox = False
        Me.MaximumSize = CType(resources.GetObject("$this.MaximumSize"), System.Drawing.Size)
        Me.MinimizeBox = False
        Me.MinimumSize = CType(resources.GetObject("$this.MinimumSize"), System.Drawing.Size)
        Me.Name = "FDetail"
        Me.RightToLeft = CType(resources.GetObject("$this.RightToLeft"), System.Windows.Forms.RightToLeft)
        Me.ShowInTaskbar = False
        Me.StartPosition = CType(resources.GetObject("$this.StartPosition"), System.Windows.Forms.FormStartPosition)
        Me.Text = resources.GetString("$this.Text")
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private mChanged As Boolean
    Private mDetail As Model10.Detail
    Private mTable As Model10.Table

    Public Event ValueChenged As EventHandler

    Private Sub FDetail_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        AddHandler USection1.ValueChanged, AddressOf OnValueChanged
        AddHandler UDetail1.ValueChanged, AddressOf OnValueChanged
    End Sub
    Private Sub btnApply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnApply.Click
        Application.DoEvents()
        Cursor.Current = Cursors.WaitCursor
        '----------------------------------
        Try
            Dim dtl As New Model10.Detail
            USection1.Write(dtl) : UDetail1.Write(dtl)
            If mDetail Is Nothing Then
                If Not mTable Is Nothing Then mTable.Detail = dtl
                mDetail = dtl
            Else
                USection1.Write(mDetail) : UDetail1.Write(mDetail)
            End If
            dtl = Nothing

            mChanged = True
            btnApply.Enabled = False
            RaiseEvent ValueChenged(Me, New EventArgs)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        '----------------------------------
        Cursor.Current = Cursors.Default
    End Sub
    Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
        btnApply.PerformClick()
        If Not btnApply.Enabled Then DialogResult = DialogResult.OK
    End Sub

    Protected Sub OnValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        btnApply.Enabled = True
        RaiseEvent ValueChenged(Me, New EventArgs)
    End Sub

    Public Property Changed() As Boolean
        Get
            Return mChanged
        End Get
        Set(ByVal Value As Boolean)
            mChanged = Value
        End Set
    End Property
    Public Property Detail() As Model10.Detail
        Get
            Return mDetail
        End Get
        Set(ByVal Value As Model10.Detail)
            mDetail = Value
        End Set
    End Property
    Public Property Table() As Model10.Table
        Get
            Return mTable
        End Get
        Set(ByVal Value As Model10.Table)
            mTable = Value
        End Set
    End Property

    Public Sub Fill()
        UDetail1.Prepare()
        If mDetail Is Nothing Then
            Dim dtl As New Model10.Detail
            USection1.Read(dtl) : UDetail1.Read(dtl)
            dtl = Nothing

            btnApply.Enabled = True
        Else
            USection1.Read(mDetail) : UDetail1.Read(mDetail)

            btnApply.Enabled = False
        End If
        mChanged = False
    End Sub
    Public Sub New(ByVal table As Model10.Table, ByVal detail As Model10.Detail)
        MyBase.New()
        InitializeComponent()

        mDetail = detail
        mTable = table
        Fill()
    End Sub
End Class
